<?php

/**
 * NewItem filter form.
 *
 * @package    jobeet
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class NewItemFormFilter extends BaseNewItemFormFilter
{
  public function configure()
  {
	$ar = array(0 => '--all--') + Doctrine::getTable('BannerGroup')->findArrayOfApropriateStructureElements();

	$this->widgetSchema['relatives'] = new sfWidgetFormSelect(array('choices' =>
		$ar ) );
	$this->validatorSchema['relatives'] = new sfValidatorPass(array('required' => false));


	$this->widgetSchema['slug'] = new sfWidgetFormFilterInput(array('with_empty' => false));
	$this->widgetSchema['slug']->setLabel('URL');

	$this->widgetSchema['modified_before'] =  new sfWidgetFormInput(array(),array('class' => 'datepicker'));
	$this->validatorSchema['modified_before'] = new sfValidatorPass(array('required' => false));
	
	
  }

    protected function addModifiedBeforeColumnQuery(Doctrine_Query $query, $field, $values) {
		$datetime = date('Y-m-d 00:00:00',strtotime($values));
		$query->addWhere($query->getRootAlias() . ".updated_at <= ?", $datetime);
		return $query;
    }

	
  
    protected function addRelativesColumnQuery(Doctrine_Query $query, $field, $values) {
    	if( $values ){
			$query->innerJoin('r.NewsGroup ng ')
					->innerJoin( 'ng.StructureNewsGroup sng WITH sng.structure_id = ?', $values );
			
    	}
    }
    
	public function getFields()
	{
		return array_merge( parent::getFields(), array('relatives' => 'Text', //using default search because it is on object1 and this class extends Object1Filter
				) );
	}
}
